package com.golden.f16;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.object.AnimatedSprite;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.PlayField;
import com.golden.gamedev.object.SpriteGroup;
import com.golden.gamedev.object.background.ImageBackground;
import com.golden.gamedev.util.ImageUtil;


public class f16 extends Game{

	  public AnimatedSprite bill_rizer;
	  PlayField playField ;
	  SpriteGroup SOLDIER;
	  Background background;
	  public static final long BILL_RIZER_DELAY = 120;
	public void initResources() {
		// TODO Auto-generated method stub
		bill_rizer = new AnimatedSprite(getImages("D:/mdktool/contra.png", 6, 2));
		BufferedImage image = getImage("D:/mdktool/bg2.png");

        image = ImageUtil.resize(image, 400, 600);
        background = new ImageBackground(image);
        playField = new PlayField(background);
        bill_rizer.setLocation(50, 50);

		SOLDIER = playField.addGroup(new SpriteGroup("Marines"));
		SOLDIER.add(bill_rizer);
		bill_rizer.setAnimationFrame(0, 5);
		bill_rizer.setAnimate(true);
		bill_rizer.setLoopAnim(true);
		bill_rizer.getAnimationTimer().setDelay(BILL_RIZER_DELAY);


	}

	@Override
	public void render(Graphics2D g) {
		// TODO Auto-generated method stub
		playField.render(g);
	}

	@Override
	public void update(long elapsedTime) {
		// TODO Auto-generated method stub
		playField.update(elapsedTime);
		if (keyDown(KeyEvent.VK_LEFT))
		{
			bill_rizer.setHorizontalSpeed(-0.10);
			bill_rizer.setAnimationFrame(0, 5);
			bill_rizer.setAnimate(true);
			bill_rizer.setLoopAnim(true);
		}
		else if (keyDown(KeyEvent.VK_RIGHT)) {
			bill_rizer.setHorizontalSpeed(0.3);
			bill_rizer.setAnimationFrame(6, 11);
			bill_rizer.setAnimate(true);
			bill_rizer.setLoopAnim(true);
        }

			// bill_rizer.setHorizontalSpeed(0.0);
			 else if(bill_rizer.getHorizontalSpeed()>0)
			 {
				bill_rizer.setAnimationFrame(8, 8);
				bill_rizer.setHorizontalSpeed(0.0);
			 }
			 else if(bill_rizer.getHorizontalSpeed()<0)
			 {
				bill_rizer.setAnimationFrame(3, 3);
				bill_rizer.setHorizontalSpeed(0.0);
			 }




	}



public static void main(String[] args) {
	GameLoader game = new GameLoader();
	game.setup(new f16(), new Dimension(300,300), false);
	game.start();

}
}
